package com.eduhzy.ttw.teacher.mvp.ui.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.teacher.R;
import com.google.zxing.WriterException;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.yzq.zxinglibrary.encode.CodeCreator;

import butterknife.BindView;

import static com.eduhzy.ttw.commonsdk.core.Constants.QRCODE.Clazz;
import static com.eduhzy.ttw.commonsdk.core.Constants.QRCODE.Person;

/**
 * @author xubo
 */
@Route(path = RouterHub.APP_GENERATECODEACTIVITY)
public class GenerateCodeActivity extends BaseActivity {

    @BindView(R.id.iv_qr_code)
    ImageView ivBarCode;
    @BindView(R.id.code_tip)
    TextView codeTip;
    @Autowired(name = Constants.GENERATE_CODE)
    String generate;
    @Autowired(name = Constants.QR_CODE_TYPE)
    int type;
    private Bitmap bitmap;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_generate_code;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        switch (type) {
            case Clazz:
                codeTip.setText(Constants.CLASS_QRCODE_TIP);
                break;
            case Person:
                codeTip.setText(Constants.PERSON_QRCODE_TIP);
                break;
            default:
        }
        //二维码生成方式一  推荐此方法
//        RxQRCode.builder(generate).
//                backColor(getResources().getColor(R.color.white)).
//                codeColor(getResources().getColor(R.color.black)).
//                codeSide(800).
//                into(ivBarCode);

        try {
            bitmap = CodeCreator.createQRCode(generate, 400, 400, null);

        } catch (WriterException e) {
            e.printStackTrace();
        }
        if (bitmap != null) {
            ivBarCode.setImageBitmap(bitmap);
        }

    }

}
